var express = require('express');
var router = express.Router();

let Query = require("../tools/db")
let {getToken,verifyToken,api_url,suo} = require("../config/index")
/* 获取banner */
router.get('/banners', async function (req, res, next) {
  let sql = `SELECT id,CONCAT("${api_url}","uploads/",image_src) AS image_src,title FROM e_banners WHERE isshow=1`
  let [, result] = await Query(sql)
  res.send({
    status: 200,
    msg: "ok",
    result
  })
})
//获取同步课程 or 精品课程
router.get('/courseinfo', async (req, res, next) => {
  // 接收type
  let { type = "1" } = req.query
  //同步课程 type=1   8
  //精品课程 type=2   6
  let limit = type == "1" ? 8 : 6
  let sql1 = `SELECT id,cid,title,price,CONCAT("${api_url}","uploads/course/",image_src) AS image_src,type_name,area_name,subject_name FROM e_course WHERE type=${type} ORDER BY id DESC LIMIT ${limit}`
  let [err, result] = await Query(sql1)
  if (!err) {
    res.send({
      status: 200,
      msg: "ok",
      result: result
    })
  } else {
    next("稍后再试")
    return
  }
})


module.exports = router;
